package com.skh.string;

import java.util.HashSet;
import java.util.Set;

/**
 * @Author: skh
 * @Date: 2019/7/5 14:24
 * @Description: 唯一摩尔斯密码词
 */
public class UniqueMorseRepresentations {

    public int uniqueMorseRepresentations(String[] words) {
        Set<String> result = new HashSet<>();

        String[] map = {
                ".-",
                "-...",
                "-.-.",
                "-..",
                ".",
                "..-.",
                "--.",
                "....",
                "..",
                ".---",
                "-.-",
                ".-..",
                "--",
                "-.",
                "---",
                ".--.",
                "--.-",
                ".-.",
                "...",
                "-",
                "..-",
                "...-",
                ".--",
                "-..-",
                "-.--",
                "--.."
        };

        for (String word : words) {
            StringBuilder sb = new StringBuilder();
            char[] chars = word.toCharArray();
            for (char aChar : chars) {
                sb.append(map[aChar-97]);
            }
            result.add(sb.toString());
        }

        return result.size();
    }

    public static void main(String[] args) {
        int a = 'a' - 97;
        int A = 'A';
        System.out.println("a = " + a);
        System.out.println("a = " + A);
    }
}
